package com.lyf.shop.entity;

public class Page {
    private Integer pageIndex;//页码
    private Integer pageSize;//每页显示行数
    private Integer totalCount;//数据总行数
    private Integer totalPages;//最大页数
    private Integer startRows;//起始下标

    public Page(Integer pageIndex, Integer pageSize, Integer totalCount) {
        if (pageSize<1){
            this.pageSize = pageSize;
        }else{
            this.pageSize = pageSize;
        }
        this.totalCount = totalCount;
        //计算最大页数
        this.totalPages = totalCount%pageSize==0?totalCount/pageSize:(totalCount/pageSize)+1;
        if(pageIndex<1){
            this.pageIndex = 1;
        }else if(pageIndex>=totalPages){
            this.pageIndex = totalPages;
        }else{
            this.pageIndex = pageIndex;
        }
        this.startRows = (this.pageIndex-1)*this.pageSize;
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }
}

